package com.welsy.classroom.business
{
	import mx.controls.Alert;
	import com.welsy.usermgt.vo.UserVO;
	import com.adobe.cairngorm.business.ServiceLocator;
	import mx.rpc.soap.mxml.WebService;
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.logging.Log;
	import com.welsy.usermgt.vo.ClassVO;
	import flash.xml.XMLNode;
	import mx.collections.ArrayCollection;
	import mx.rpc.soap.Operation;
	import com.welsy.util.NamespaceLocator;
	import com.welsy.iter.vo.IterVO;

	
	public class SaveItersDelegate 
	{
		private var responder : IResponder;
		private var service : Object;
		
		public function SaveItersDelegate( responder : IResponder ) {
			//Recorded in Services.mxml
			this.responder = responder;
			this.service = ServiceLocator.getInstance().getWebService("ClassroomServices") as WebService;
		}
				
		public function saveItinera(classId:int, iters : ArrayCollection) : void {
			
			var oper : Operation = Operation(WebService(service).getOperation("SaveIters"));
			var root : String = "<SaveIters xmlns='http://Welsy.ServiceContracts/2007/02'>";
			root += "<SaveItersRequest xmlns='"+NamespaceLocator.CLASSROOM_DATATYPES+"'>";

			var tag_classroom : String = "<ClassroomId>"+classId+"</ClassroomId>"
			var tag_users : String = "<IterIdCollection>";
			for each(var iter : IterVO in iters) {
				tag_users += "<decimal>"+iter.id+"</decimal>";
			}	
			tag_users += "</IterIdCollection>"

			root += tag_classroom;
			root += tag_users;
			root += "</SaveItersRequest>";
			root += "</SaveIters>";
			
			oper.request = new XML(root);	

			var token : AsyncToken = service["SaveIters"].send();
			token.addResponder(responder);
						
		}
	}	
}